<template>
  <!-- 点击跳转到详情页 - 使用动态id参数 -->
  <van-cell @click="goToDetail">
    <template #title>
      <div class="title-container">
        <div class="logo">
          <img :src="avatar" alt="Logo" />
        </div>
        <div class="con">
          <p class="con-title">{{stem}}</p>
          <div class="info">
            <span class="creator">{{creator}}</span>
            |
            <span class="createdAt">{{createdAt}}</span>
          </div>
        </div>
      </div>
    </template>
    <template #label>
      <div class="label-container">
        <div class="label">{{cleanContent}}</div>
        <!-- 将互动统计区域移至内容下方 -->
        <div class="interaction-stats">
          <div class="stat-item likes">
            <van-icon name="like" class="stat-icon" />
            <span class="stat-count">{{ likeCount }}</span>
          </div>
          <div class="stat-item collections">
            <van-icon name="star" class="stat-icon" />
            <span class="stat-count">{{ views }}</span>
          </div>
        </div>
      </div>
    </template>
  </van-cell>
</template>

<script>
export default {
  name: 'ArticleItem',
  props: {
    id: {
      type: [String, Number],
      required: true // 确保id是必填项
    },
    avatar: {
      type: String,
      default: '@/assets/images/logo.png'
    },
    stem: {
      type: String,
      default: ''
    },
    creator: {
      type: String,
      default: ''
    },
    createdAt: {
      type: String,
      default: ''
    },
    content: {
      type: String,
      default: ''
    },
    likeCount: {
      type: [String, Number],
      default: 0
    },
    views: {
      type: [String, Number],
      default: 0
    }
  },
  computed: {
    cleanContent () {
      return this.content.replace(/<.+?>/g, '')
    }
  },
  methods: {
    goToDetail () {
      // 使用动态路由跳转到详情页，并传入id参数
      this.$router.push({
        name: 'Details',
        params: {
          id: this.id
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
/* 移除了.title容器和van-cell-group相关样式，直接对van-cell进行样式设置 */
.van-cell {
  margin-bottom: 12px;
  border-radius: 12px;
  overflow: visible;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 16px;
  position: relative;

  &:after {
    display: none;
  }
}

.title-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

.con {
  flex: 1;
  min-width: 0;
}

.con-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
}

.info {
  margin-top: 4px;
  font-size: 12px;
  color: #999;

  .creator,
  .createdAt {
    display: inline-block;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }
}

.label {
  margin-top: 12px;
  font-size: 14px;
  color: #666;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  position: relative;
  z-index: 5;
}

/* 互动数据统计样式 */
.interaction-stats {
  display: flex;
  justify-content: flex-start;
  gap: 16px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #f0f0f0;
  position: relative;
  z-index: 10;
  overflow: visible;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  transition: all 0.3s ease;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  position: relative;
  z-index: 15;
  overflow: visible;

  &.likes {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 8px 20px rgba(240, 147, 251, 0.4);
    }
  }

  &.collections {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
    }
  }
}

.stat-icon {
  font-size: 16px;
  font-weight: bold;
}

.stat-count {
  font-size: 13px;
  font-weight: 600;
  font-family: 'Arial', sans-serif;
}

/* 响应式调整 */
@media screen and (max-width: 768px) {
  .van-cell {
    margin-bottom: 10px;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
    padding: 14px;
  }

  .title-container {
    gap: 10px;
  }

  .logo {
    width: 36px;
    height: 36px;
  }

  .con-title {
    font-size: 15px;
  }

  .info {
    font-size: 11px;
    margin-top: 3px;
  }

  .label {
    margin-top: 10px;
    font-size: 13px;
  }

  .interaction-stats {
    margin-top: 14px;
    padding-top: 14px;
    gap: 12px;
    overflow: visible;
  }

  .stat-item {
    padding: 5px 10px;
    font-size: 12px;
    gap: 5px;

    .stat-icon {
      font-size: 14px;
    }

    .stat-count {
      font-size: 12px;
    }
  }
}

@media screen and (max-width: 480px) {
  .van-cell {
    margin-bottom: 8px;
    border-radius: 10px;
    padding: 12px;
  }

  .title-container {
    gap: 8px;
  }

  .logo {
    width: 32px;
    height: 32px;
  }

  .con-title {
    font-size: 14px;
    -webkit-line-clamp: 1;
  }

  .info {
    font-size: 10px;
    margin-top: 2px;

    .creator,
    .createdAt {
      max-width: 100px;
    }
  }

  .label {
    margin-top: 8px;
    font-size: 12px;
    -webkit-line-clamp: 2;
  }

  .interaction-stats {
    margin-top: 12px;
    padding-top: 12px;
    gap: 10px;
    overflow: visible;
  }

  .stat-item {
    padding: 4px 8px;
    font-size: 11px;
    gap: 4px;

    .stat-icon {
      font-size: 12px;
    }

    .stat-count {
      font-size: 11px;
    }
  }
}
</style>
